#include "LuaFlightPath.h"

#include "luawrapper.hpp"
#include "luawrapperutil.hpp"

#include "FlightPath.h"
#include "FlightDynamicModel.h"

static int FlightPath_push_back(lua_State *L)
{
	FlightPath *flightPath = luaW_check<FlightPath>(L, 1);
	FlightDynamicModel *fdm = luaW_check<FlightDynamicModel>(L, 2);

	flightPath->push_back(*fdm);

	return 0;
}

static int FlightPath_at(lua_State *L)
{
	FlightPath *flightPath = luaW_check<FlightPath>(L, 1);
	int index = luaL_checknumber(L, 2);
	FlightDynamicModel * fdm = &flightPath->at(index);

	luaW_push<FlightDynamicModel>(L, fdm);
	return 1;
}

static int FlightPath_size(lua_State *L)
{
	FlightPath *flightPath = luaW_check<FlightPath>(L, 1);
	lua_pushinteger(L, flightPath->size());
	return 1;
}

static luaL_Reg FlightPath_table[] =
{
	{ NULL, NULL }
};

static luaL_Reg FlightPath_metatable[] =
{
	{ "push_back", FlightPath_push_back },
	{ "at", FlightPath_at },
	{ "size", FlightPath_size },
	{ NULL, NULL }
};

extern int luaopen_FlightPath(lua_State* L)
{
	luaW_register<FlightPath>(L, "FlightPath", FlightPath_table, FlightPath_metatable);
	return 1;
}

